<?php

class M_gperiods Extends CI_Model
{
	private $__table = 'grading_periods';
	
	public function __construct()
	{
		parent::__construct();
	}
	
	public function get_gperiods($id = FALSE)
	{
		$this->load->database();
		if($id == FALSE){
			$data = $this->db->get($this->__table);
		}else{
			$data = $this->db->where('gp_id',$id)->get($this->__table);	
		}
		return $data->num_rows() >= 1 ? $data->result() : FALSE;
	}
	
	public function count_gperiods()
	{
		return $this->db->count_all($this->__table);
	}
	
	public function get_id_of_current_gperiod(){
		$query = $this->db->where('is_set','yes')->select('gp_id')->get($this->__table);
		if($query->num_rows () > 0 ){
			$row = $query->row();
			return $row->gp_id;
		}
	}
	
	public function get_current_gperiod()
	{
		$query = $this->db->where('is_set','yes')->get($this->__table);
		return $query->num_rows() > 0 ? $query->result() : FALSE;
	}
	
	public function get_current_gperiods_value($data)
	{
		$query = $this->db->select($data)->where('is_set','yes')->get($this->__table);
		if($query->num_rows() > 0 )
		{
			$row = $query->row();
			return $row->$data;
		}
	}
	
	
	public function get_specific_coloumn($data)
	{	
		$query = $this->db->select($data)->get($this->__table);
		return $query->num_rows() > 0 ? $query->result() : FALSE;
	}

}